package development;

import java.util.Hashtable;

import javax.microedition.lcdui.Image;

import state.Alert;
import state.GameConstants;
import state.GameForm;
import state.Key;
import state.component.BottomBar;
import state.component.Event;
import state.component.EventListener;
import state.component.Menu;
import state.component.MenuStyle;
import state.font.FontManager;
import state.util.Color;
import state.util.ImageUtil;

public class FrmTestBottomBar extends GameForm implements EventListener {
  private BottomBar bottomBar;
  
  private static GameForm singleton;
  
  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmTestBottomBar();
    }
    return singleton;
  }

  public void init(Hashtable parameters) {
    Image menuItemBackground = ImageUtil.getImage("bg_menu.png");
    menuItemBackground = ImageUtil.joinAndCreateImages(menuItemBackground, 120, menuItemBackground.getHeight());
    
    MenuStyle MENU_STYLE = new MenuStyle();
    MENU_STYLE.setBorderColor(Color.WHITE_CODE);
    MENU_STYLE.setItemBackgroundImage(menuItemBackground);
    MENU_STYLE.setForceGroundColor(Color.WHITE_CODE);
    MENU_STYLE.setFocusFgColor(0x7F0300);
    MENU_STYLE.setItemHeight(20);
    MENU_STYLE.setItemWidth(120);
    MENU_STYLE.setFont(FontManager.getFont(FontManager.FONT_SIZE_8));
    MENU_STYLE.setTextDx(5);
    MENU_STYLE.setTextDy(2);
    
    Menu menu = new Menu(new String[]{"Đăng ký TK", "Quên mật khẩu", "Giới thiệu", "Hotline hỗ trợ", "Thoát"}, 
        this, MENU_STYLE, 0, GameConstants.SCREEN_HEIGHT - 45);
    
    bottomBar = new BottomBar(manager, 25);
    Image bottomBarImage = ImageUtil.getImage("bg_footer.png");
    bottomBarImage = ImageUtil.joinAndCreateImages(bottomBarImage, Constants.SCREEN_WIDTH, bottomBarImage.getHeight());
    bottomBar.setImage(bottomBarImage);
    bottomBar.setLabels("Menu", "Center menu", "Back");
    bottomBar.setLeftMenu("Menu", menu);
  }
  
  public void keyReleased(int keyCode) {
    if (bottomBar.isMenuShowing()) {
      return;
    }
    
    switch (keyCode) {
    case Key.SOFT_RIGHT:
      Global.nextState(FrmMenu.instance(), null);
      break;
    case Key.FIRE:
      Global.alert.showAlert(this, Alert.OK_TYPE, "User pressed FIRE");
      break;
    }
  }
  
  public void onActionPerform(Event event) {
  }
  
  protected void destroy() {
    bottomBar.detroy();
    bottomBar = null;
  }
}
